<template>
	<view>
		<view class="zy-status-bar"></view>
		
		<view class="zy-ph-50">
			<view class="zy-register-title" > 你的</view>
			<view class="zy-register-title2 zy-mb-50" > 生日是？</view>
			
		<!-- 	<view class="zy-row">
				<picker mode="date" fields="day">
				</picker>
				<!-- <view style="flex:2">
					<view class="zy-row-center zy-text-whitegrey-lg-bold" style="font-size: 64rpx;">YYYY</view>
					<zy-line></zy-line>
				</view>
				<view style="flex:1; margin: 0 50rpx;" >
					<view class="zy-row-center zy-text-whitegrey-lg-bold" style="font-size: 64rpx;">MM</view>
					<zy-line></zy-line>
				</view>
				<view style="flex:1">
					<view class="zy-row-center zy-text-whitegrey-lg-bold" style="font-size: 64rpx;">DD</view>
					<zy-line></zy-line>
				</view> -->
			<!-- </view> --> -->
				
			<picker-view :indicator-style="indicatorStyle" :value="value" @change="bindChange" class="picker-view"
				mask-style="background:transparent;">
				<picker-view-column>
					<view class="item" :class="{ select: item == year }" v-for="(item, index) in years" :key="index">
						{{ item }}年
					</view>
				</picker-view-column>
				<picker-view-column>
					<view class="item" :class="{ select: item == month }" v-for="(item, index) in months" :key="index">
						{{ item }}月
					</view>
				</picker-view-column>
				<picker-view-column>
					<view class="item" :class="{ select: item == day }" v-for="(item, index) in days" :key="index">
						{{ item }}日
					</view>
				</picker-view-column>
			</picker-view>
				
			<zy-register-bottom @next="next"></zy-register-bottom>
		</view>
	</view>
</template>

<script>
	import RouteUtil from '@/main/common/RouteUtil.js';
	import CacheUtil from '@/main/common/CacheUtil';
	export default {
		data() {
			const date = new Date();
			const years = [];
			const year = date.getFullYear();
			const months = [];
			const month = date.getMonth() + 1;
			const days = [];
			const day = date.getDate();
			for (let i = 1900; i <= date.getFullYear() - 18; i++) {
				years.push(i);
			}
			for (let i = 1; i <= 12; i++) {
				months.push(i);
			}
			for (let i = 1; i <= 31; i++) {
				days.push(i);
			}
			return {
				years,
				year,
				months,
				month,
				days,
				day,
				value: [years.length - 1, month - 1, day - 1],
				indicatorStyle: `height: 50px`,
				data: {},
			};
		},
		onLoad() {
			this.data = CacheUtil.getRegisterUser();
			this.$nextTick(() => {
				let e = {
					detail: {
						value: this.value
					}
				};
				this.bindChange(e);
			});
		},
		methods: {
			back() {
				uni.navigateBack();
			},
			bindChange: function(e) {
				const val = e.detail.value;
				this.year = this.years[val[0]];
				this.month = this.months[val[1]];
				this.day = this.days[val[2]];
				this.data.birthday = this.years[val[0]] + '-' + this.months[val[1]] + '-' + this.days[val[2]];
			},
			next() {
				CacheUtil.setRegisterUser(this.data)
				RouteUtil.toRegisterSex()
			},

		}
	};
</script>

<style lang="scss">
	.picker-view {
		width: 100%;
		height: 600rpx;
		margin: 0 auto;
	}
	
	.item {
		height: 50px;
		line-height: 50px;
		text-align: center;
		color: #b3b3b3;
	}
	
	.item.select {
		color: #fff;
		font-size: 36rpx;
		font-weight: 500;
	}
</style>